<script language='JavaScript' type='text/javascript'>
function showDiv(divId)
{
	 
	 if (document.getElementById(divId).style.display=="none")
	 {
	   document.getElementById(divId).style.display='block';
	 }
	 
	 if(divId=="login_div_exist")
	 {
	 	document.getElementById("login_div_new").style.display='none';
	 }
	 
	 if(divId=="login_div_new")
	 {
	 	document.getElementById("login_div_exist").style.display='none';
	 }
	
}

function hideDiv(divId)
{
	 		document.getElementById(divId).style.display='none';
	
}
</script>

<div id="maincontent">

<%= render :partial => "shared_common_files/data_area_help_bar" %>

<h2>Backup</h2>
	<% for name in [:notice, :warning, :message] %>
    <% if flash[name] %>
      <%= "<div class='message-fatal'> #{flash[name]} </div>" %>
    <% end %>
  <% end %>
  
    <% for name in [:simplemsg] %>
    <% if flash[name] %>
      <%= "<div class='message-justmsg'> #{flash[name]} </div>" %>
    <% end %>
  <% end %>		
  
 
  		
	<%= start_form_tag({:action => 'savebackup'},{:class => 'appform'}) %>
		
		<fieldset>
		
			<h3>Tables</h3>
		
			<b>These core Ajuby tables will be backed up:</b><br/>
		<div >
			<table align="center" cellspacing="5" cellpadding="5">
			<%for table_name in @tables%>
			<tr> <td bgcolor="#f1f1f1" width="50%" align="left">
			<!-- input type="hidden" name="tablename" value="<%=table_name%>" / -->
			<li><%=table_name%></li>
			</td></tr>
			<%end%>
			</table>	   
		</div>
		
		
		</fieldset>

	
		<fieldset>
			
			<h3>Backup Options</h3>
				
			<div class="f-radio-wrap">
		
				<b>What to do with the backup file:</b>
		
				<fieldset>
				
				<%if(@access_key == '' && @secret_key == '')%>
				
					<label for="name">
					<input type="radio" name="savetype" value="bucket" class="f-radio" onclick = "javascript: showDiv('error_div');" />
					Save to Amazon bucket</label>
				
				<%elsif(@connectioncheck == '')%>
				
					<label for="name">
					<input type="radio" name="savetype" value="bucket" class="f-radio" onclick = "javascript: showDiv('check_div');" />
					Save to Amazon bucket</label>
				
				<%else%>
				
					<label for="name">
					<input type="radio" name="savetype" value="bucket" class="f-radio" onclick = "javascript: showDiv('login_div');" />
					Save to Amazon bucket</label>
				
				<%end%>
				
				<div class='message-justmsg' style="padding: 0px; border: 0px; margin-bottom: 5px; "  > 
					<font color="black">
						<div  id="error_div" style="display: none;">		  							
  							
							<br/>&nbsp;&nbsp;&nbsp;If you have an account with Amazon S3 click on <a href="/integration/edit?node=amazonws"">Save your Access and Secret key</a>. <br/><br/>&nbsp;&nbsp;&nbsp;If you donot have an account please Sign up for S3 and get your keys <a href="http://aws.amazon.com/s3">Create a new account with Amazon S3</a>.<br/><br/> 
							
						</div>				
					 </font>
				</div>	
				
				<div class='message-justmsg' style="padding: 0px; border: 0px; margin-bottom: 5px; "  > 
					<font color="black">
						<div  id="check_div" style="display: none;">		  							
  							
							<br/>&nbsp;&nbsp;&nbsp;You have entered either wrong Access Key or Secret Key. Please try again! <a href="/integration/edit?node=amazonws">Save your Access and Secret key</a>.<br/><br/>
							
						</div>				
					 </font>
				</div>	
				
				<div class='message-justmsg' style="padding: 0px; border: 0px; margin-bottom: 5px;"  > 
					<font color="black">
						<div  id="login_div" style="display: none;">
						<br/>					
				
				<input type="radio" name="savetypeamazon" value="fetchbucket" onclick = "javascript: showDiv('login_div_exist');"/>
				Save to existing Bucket<br/><br/>
				
								
										<div  id="login_div_exist" style="display: none;">
  											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select Bucket: 
  													<select name="selectbucketname" style="margin-left:10px;">
    													<%for bucketlist in @bucketlist%>
															<option value="<%=bucketlist%>"><%=bucketlist%></option>
							        					<%end%>
    												</select><br/>
  										</div><br/>
 				    				
				
				
				
				<input type="radio" name="savetypeamazon" value="newbucket" onclick = "javascript: showDiv('login_div_new');"/>
				Create a new Bucket<br/><br/>
				
				
										<div  id="login_div_new" style="display: none;">
  											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter the Bucket name: <input class="f-name" id="bucket" name="bucket" style="background-color: #f4f4f4; color: #366188;" value="" size="30" /><br/>
										</div>
  					      	
							
							<br/>
		     	        </div>
 				    </font>
			    </div>
				
				
				<%if(@access_key == '' && @secret_key == '')%>
				
				<label for="name">
				<input type="radio" name="savetype" value="server" class="f-radio" onclick = "javascript: hideDiv('error_div');" />
				Save to server</label>
				
				<label for="name">
				<input type="radio" checked="checked" name="savetype" value="download" class="f-radio" onclick = "javascript: hideDiv('error_div');" />
				Download to your computer</label>
				
				<label for="name">
				<input type="radio" name="savetype" value="email" class="f-radio" onclick = "javascript: hideDiv('error_div');" />
				Email backup to:</label><b><input id="email" class="f-name" type="text" style="margin-left: 110px; background-color: #f4f4f4; color: #366188;" value="" name="email" size="30" /></b>
				
				<%elsif(@connectioncheck == '')%>
				
				<label for="name">
				<input type="radio" name="savetype" value="server" class="f-radio" onclick = "javascript: hideDiv('check_div');" />
				Save to server</label>
				
				<label for="name">
				<input type="radio" checked="checked" name="savetype" value="download" class="f-radio" onclick = "javascript: hideDiv('check_div');" />
				Download to your computer</label>
				
				<label for="name">
				<input type="radio" name="savetype" value="email" class="f-radio" onclick = "javascript: hideDiv('check_div');" />
				Email backup to:</label><b><input id="email" class="f-name" type="text" style="margin-left: 110px; background-color: #f4f4f4; color: #366188;" value="" name="email" size="30" /></b>
				
				
				<%else%>
				
				<label for="name">
				<input type="radio" name="savetype" value="server" class="f-radio" onclick = "javascript: hideDiv('login_div');" />
				Save to server</label>
				
				<label for="name">
				<input type="radio" checked="checked" name="savetype" value="download" class="f-radio" onclick = "javascript: hideDiv('login_div');" />
				Download to your computer</label>
				
				<label for="name">
				<input type="radio" name="savetype" value="email" class="f-radio" onclick = "javascript: hideDiv('login_div');" />
				Email backup to:</label><b><input id="email" class="f-name" type="text" style="margin-left: 110px; background-color: #f4f4f4; color: #366188;" value="" name="email" size="30" /></b>
				
				<%end%>
				
				
				<div class="f-submit-wrap">
					<input type="hidden" name="do_backup" id="do_backup" value="backup" />
			  		<!-- %=submit_tag "Backup!" % -->
			  		<%= image_submit_tag "/themes/odotclassic/images/btn_submit.png", :border => 0 %>
			  		<!-- input type="button" value="Cancel" onclick="javascript:history.go(-1);"/ -->
			  		<a href="javascript:history.go(-1);"><img src="/themes/odotclassic/images/btn_cancel.gif"/></a>
				</div>  
				
				</fieldset>
			
			</div>
		
		</fieldset>		

	<%= end_form_tag %>

	<%= start_form_tag({:action => 'schedulebackup'},{:class => 'appform'}) %>	
		<div class="req"><b>*</b>Required Information </div>
		
		<fieldset>
	
			<h3>Scheduled Backup</h3>
	
			<div class="f-radio-wrap">
		
				<b>Schedule:</b>
		
				<fieldset>
				
				<label for="name">
				<input type="radio" name="scheduletype" checked="checked" value="never" class="f-radio" />
				Never</label>
				
				<label for="name">
				<input type="radio" name="scheduletype" value="hourly" class="f-radio"/>
				Once Hourly</label>
				
				<label for="name">
				<input type="radio" name="scheduletype" value="daily" class="f-radio"/>
				Once Daily</label>
				
				<label for="name">
				<input type="radio" name="scheduletype" value="weekly" class="f-radio"/>
				Once Weekly</label>
				
				<label for="name" style="padding-left: 110pt; line-height:1;"><b><span class="req">*</span>Email backup to:</b>
				<b><input class="f-name" id="email" name="email" style="background-color: #f4f4f4; color: #366188;" value="" size="30" /></b>
				</label>
			
				<div class="f-submit-wrap">
			  	<!-- %=submit_tag "Submit" % -->
			  	<%= image_submit_tag "/themes/odotclassic/images/btn_submit.png", :border => 0 %>
			  	<a href="javascript:history.go(-1);"><img src="/themes/odotclassic/images/btn_cancel.gif"/></a>
				</div> 

				</fieldset>
				
			</div>	
			
		</fieldset>
	     
	<%= end_form_tag %>
	

</div>  